<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of UploadController
 *
 * @author Administrator
 */

namespace frontend\api\controllers;

use frontend\bean\Attachment;
use Yii;

class UploadController extends BaseController {

    public $enableCsrfValidation = false;
    
   
    //put your code here

    public function actionGetUploadToken() {
        $srv = \Yii::$container->get('UploadService');
        $token = $srv->getUploadToken();
        $this->_sendResponse(array('uptoken'=>$token));
    }
    
    
    

    public function actionCallback() {
        //check
      $srv = \Yii::$container->get('UploadService');
          
      $body = $this->getInput('input', 'body');
       // $body = '{"fname":"1918162812.jpg", "fkey":"1918162812.jpg", "desc":"", "uid":1}';
      $body = json_decode($body, true);
        // file_put_contents('php://input', $body);
      $bean = new Attachment();
      $bean->setUid($body['uid'])
            ->setFname($body['fname'])
            ->setKey($body['fkey'])
            ->setDescription($body['desc']);
        
      $aid = $srv->addAttachment($bean);
      $resp = array('ret' => 'success','aid'=> $aid );
      $this->_sendResponse($resp);
    }

}
